import java.util.Stack;

public class Solution394 {
    public String decodeString(String s) {
        Stack<StringBuilder> stack=new Stack<>();
        Stack<Integer> stack1=new Stack<>();
        stack.push(new StringBuilder());
        for (int t=0;t<s.length();t++){
            char c=s.charAt(t);
            if (c>='0' && c<='9'){
                int m=0;
                while (s.charAt(t)!='['){
                    m=m*10+s.charAt(t)-'0';
                    t++;
                }
                t--;
                stack1.push(m);
            }else if (c=='['){
                stack.push(new StringBuilder());
            }else if (c==']'){
                StringBuilder p=stack.pop();
                int q=stack1.pop();
                for (int i=0;i<q;i++){
                    stack.peek().append(p);
                }
            }else{
                stack.peek().append(c);
            }
        }
        return stack.pop().toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution394().decodeString("3[a]2[bc]"));
    }
}
